//
//  MainViewController.m
//  01_kakin
//
//  Created by jon due on 12/03/19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"

// menuのRect
#define Rect_MenuDisplay    CGRectMake(0, 425 ,320, 55)
#define Rect_MenuHide       CGRectMake(0, 480 ,320, 55)


@implementation MainViewController

@synthesize menuView = _menuView;
@synthesize hukidashiView = _hukidashiView;
@synthesize titleView = _titleView;
@synthesize startBtn = _startBtn;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    isPlay = NO;
    
    /*=== menuBarを追加 ===*/
    self.menuView = [[ menuView alloc ]initWithNibName:@"menuView" bundle:nil];
    self.menuView.view.frame = Rect_MenuHide;
    self.menuView.delegate = self;
    [ self.view addSubview:self.menuView.view ];
    
    /*=== 吹き出し追加 ===*/
    self.hukidashiView = [[ SAHukidashi alloc ]initReloadMode:CGRectMake(15, 10, 200, 0) mode:HDReloadModeAuto];
    [ self.hukidashiView setObject ];
    [ self.view addSubview:self.hukidashiView ];
    [ self.hukidashiView performSelector:@selector(startHukidashi) withObject:nil afterDelay:10.0 ];
    
    // menu登場アニメ
    [UIView animateWithDuration:2.0
                     animations:^{ self.menuView.view.frame = Rect_MenuDisplay; }
    ];
    
    /*=== title追加 ===*/
    [self.view addSubview:self.titleView ];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
    _titleView = nil;
    _startBtn = nil;
}

-(void)dealloc{
    [ _menuView release ];
    [ _hukidashiView release ];
    [ _titleView release ];
    
    [ super dealloc ];
}

-(void)viewWillAppear:(BOOL)animated{
    [ super viewWillAppear:animated ];
    
    self.navigationController.navigationBarHidden = YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/* ============================================================================== */
#pragma mark - menuDelegate
/* ============================================================================== */

-(void)A_BtnAction:(UIButton*)btn{
    // 電卓画面
    DenTakuViewController *dentaku = [[ DenTakuViewController alloc ]initWithNibName:@"DenTakuViewController" bundle:nil];
    [ (SANavigationController*)self.navigationController SApushViewController:dentaku animated:SAAnimationTypeTop ];
    [ dentaku release ];
    
}
-(void)B_BtnAction:(UIButton*)btn{
    
}
-(void)C_BtnAction:(UIButton*)btn{
    
    // サウンドコレクション
    SoundCollectionController *soundView = [[ SoundCollectionController alloc ]initWithNibName:@"SoundCollectionController" bundle:nil];
    [ (SANavigationController*)self.navigationController SApushViewController:soundView animated:SAAnimationTypeTop ];
    [ soundView release ];
    
}
-(void)D_BtnAction:(UIButton*)btn{
    
    // 設定画面
    Kakin_settingViewController *settingView = [[ Kakin_settingViewController alloc ]initWithNibName:@"Kakin_settingViewController" bundle:nil];
    [ (SANavigationController*)self.navigationController SApushViewController:settingView animated:SAAnimationTypeDown ];
    [ settingView release ];
}


/* ============================================================================== */
#pragma mark - button Action
/* ============================================================================== */

-(IBAction)startBtnTouchUpInside:(UIButton*)sender{
    
    // アニメーション
    [UIView animateWithDuration:2.0 animations:^{ self.titleView.alpha = 0.0; } 
                     completion:^(BOOL finished) {[ self.titleView removeFromSuperview ];}
     ];
}

-(IBAction)TwitterBtnTouchInside:(UIButton*)sender{
    
    // TwitterDialogを追加
    DETweetComposeViewController *tcvc = [[[DETweetComposeViewController alloc] init] autorelease];
    [tcvc addImage:[UIImage imageNamed:IMG_Logo]];
    [tcvc addURL:[NSURL URLWithString:@"http://www.DoubleEncore.com/"]];
    [tcvc addURL:[NSURL URLWithString:@"http://www.apple.com/ios/features.html#twitter"]];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentModalViewController:tcvc animated:YES];
    
}


/* ============================================================================== */
#pragma mark - touchUp inside
/* ============================================================================== */

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    return;
    
    // soundFileを選択する処理
    
    
    isPlay = YES;
    // 再生
    SASoundPlayer *player = [[ SASoundPlayer alloc ]init];
    player.delegate = self;
    [player play:@""];
    
    [ player release ];
}

/* ============================================================================== */
#pragma mark - SASoundDelegate
/* ============================================================================== */

// playerが再生終了したら
-(void)soundPlayer:(AVAudioPlayer*)player{
    isPlay = NO;
}


@end
